<template>
  <div>
  <van-list
  @load="onLoad"
>
  <van-cell v-for="item in list" :key="item.id" :title="item.name" >
  <van-button @click='addprescription(item.id)'>开具处方</van-button>
  </van-cell>


</van-list>


<van-dialog v-model:show="show" title="标题">
 
 <van-form @submit="onSubmit">
  <van-cell-group inset>
    <van-field
      v-model="sform.diagnosis"
      name="diagnosis"
      label="病例"
      placeholder="病例"
      :rules="[{ required: true, message: '请填写病例' }]"
    />
    <van-field
      v-model="sform.prescription"
      name="prescription"
      label="处方"
      placeholder="处方"
      :rules="[{ required: true, message: '请填写处方' }]"
    />

    <van-checkbox-group v-model="checked" shape="square">
  <van-checkbox :name="i.id" v-for="i in dlist">{{i.name}}</van-checkbox>
  
</van-checkbox-group>


  </van-cell-group>
  <div style="margin: 16px;">
    <van-button round block type="primary" native-type="submit">
      提交
    </van-button>
  </div>
</van-form>

</van-dialog>


  
  </div>
</template>

<script>
import { ref } from 'vue';
import http from "../../http";

export default {
  setup() {
    const list = ref([]);
    const checked = ref([]);
    const dlist = ref([{"id":1,'name':'A药'},{"id":2,'name':'陈述'}])
    const show = ref(false);
    const sform = ref({"prescription":'','diagnosis':'','id':0,'dlist':[]})
    const onLoad = () => {
      http.get('patient/?doctorid=1').then(res=>{
        list.value = res.data.list
      })
    };

    const addprescription =(id)=>{
       //获取所有药品信息
        sform.value.id=id
        show.value=true
    }

    const onSubmit =()=>{
      sform.value.dlist= dlist.value
      http.post('',sform.value).then(res=>{
        
      })
    }

    return {
      list,
      onLoad,
      addprescription,
      show,
      onSubmit,
      sform,
      checked,
      dlist,
    };
  },
};

</script>

<style>

</style>